package com.jwell.bigdata.ui.main

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentPagerAdapter
import android.support.v4.view.ViewPager
import android.support.v7.app.AppCompatActivity
import android.view.View
import com.jwell.bigdata.R
import com.jwell.bigdata.fragment.GFETFragment
import com.jwell.bigdata.fragment.LZBFragment
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    val mFragmentList = mutableListOf<Fragment>()
    var mLZBFragment = LZBFragment.getInstance()
    var mGFETFragment = GFETFragment.getInstance()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        ib_left.setOnClickListener {
            view_pager.currentItem = 0
        }
        ib_right.setOnClickListener {
            view_pager.currentItem = 1
        }
        mFragmentList.add(mLZBFragment)
        mFragmentList.add(mGFETFragment)
        view_pager.offscreenPageLimit = 2
        view_pager.adapter = object : FragmentPagerAdapter(supportFragmentManager) {
            override fun getItem(p0: Int) = mFragmentList[p0]
            override fun getCount() = 2
        }
        view_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrollStateChanged(p0: Int) {
            }

            override fun onPageScrolled(p0: Int, p1: Float, p2: Int) {
            }

            override fun onPageSelected(index: Int) {
                ib_right.visibility = if (index == 1) View.GONE else View.VISIBLE
                ib_left.visibility = if (index == 0) View.GONE else View.VISIBLE
            }
        })
    }
}
